//浏览房间详情
			//防弹层
var room_list = $(".item.recommend-item");                          //首页房间列表
var room_list_li = $(".dl-room-type.js_roomlist li");				//首页房间li
var room_detail = document.getElementById("ui-view-28");  			//房间详情页面

var timer = document.getElementById("ui-view-14");                     //日历页面
var timer_btn = document.getElementsByClassName("js_in_out_day")[0]; 	//日历按钮

var indate = document.getElementsByClassName("date js_indate")[0];    		//入住信息
var intime = indate.getElementsByClassName("indate--wrap")[0];        				//入住时间
var outdate = document.getElementsByClassName("date js_outdate")[0];        //离店信息
var outtime = outdate.getElementsByClassName("outdate--wrap")[0];						//离店时间

var room_text = [];
var room_img = [];
var room_pay_btn = [];
var sb=[];

var today = new Date(),
year = today.getFullYear(),
month = today.getMonth()+1,
day = today.getDate();

var todaytimeStamp = today.getTime();
var nextDaytimeStamp = todaytimeStamp+86400000;
var nextDay = new Date(nextDaytimeStamp),
nextDayString = nextDay.getFullYear()+'/'+(nextDay.getMonth()+1)+'/'+nextDay.getDate(),
dafaultInDate = today.getFullYear()+'/'+(today.getMonth()+1)+'/'+today.getDate(),
defaultOutDate = nextDayString;

//获取时间
var my_date = new Date();
var year = my_date.getFullYear(); 		//年
var month = my_date.getMonth()+1; 		//月  ,因为从0开始，所以要加1，
var day = my_date.getDate();     		//日
var today = year+'/'+month+'/'+day; 	//今天
//明天日期
var tomorrow = function tomorrow(){
    var day3 = new Date();
    day3.setTime(day3.getTime()+24*60*60*1000);
    var s3 = day3.getFullYear()+"/" + (day3.getMonth()+1) + "/" + day3.getDate();
    return s3;
}();

intime.innerHTML =  today;                 //入店时间默认为今天
outtime.innerHTML = tomorrow;              //离店时间默认为明天






//头部图片跳转
$(".hotelimg").click(function () {
    window.location.href = "hotel.php?mod=index&act=hotelimg";
});

//跳转地图
$(".js_goto_map").click(function () {
    window.location.href = "hotel.php?mod=index&act=daohang&address=";
});

//点击首页的房间列表
// room_list_li.each(function (i) {
//     li_index=i;
//     room_text[li_index] = room_list[li_index].getElementsByClassName("cell-star room-bd js_rommimage")[0]; //房间文字描述部分
//     room_img[li_index] = room_list[li_index].getElementsByClassName("room-img")[0];    					 //房间描述图片
//     room_pay_btn[li_index] = room_list[li_index].getElementsByClassName("dl-btn-mod")[0];                  //房间预定按钮
//
//     show_detail(room_text[li_index]);				//点击文字
//     show_detail(room_img[li_index]);			    //点击图片
//
//     room_pay_btn[li_index].onclick = function () {  //点击预定按钮
//         var house_id = $(this).attr('house-id');    //获取房型id
//         goto_pay(house_id);
//     }
// })



//判断是否满房
room_list_li.each(function(i){
    li_index=i;  	//li下标   索引
    sb[li_index] = $(this).data("is_book");	//每个房间的满房条件  1为满房
    console.log()
    if(sb[li_index] ==1){ //满房
        $(this).find(".dl-btn-mod").css("background","#c7c7c7");   //预定按钮变灰

        $(this).click(function(){
            var house_id = $(this).attr('house-id');   //获取房型id
            var index_price = $(this).find('.cell-end.room-column.js_bookroom .tc .price').text();  //获取价格
            //创建房间详情页面
            create_room_html(house_id,index_price);
            $("#ui-view-28").find(".l-btn.btn--ui3.js_btn_book").attr("class","l-btn btn--ui3 js_btn_book pay-way-disable");  //页面的预定按钮变灰

            //满房提示
            $('.l-btn.btn--ui3.js_btn_book').on('click',function(){
                return 0;
            })

        })
    }else{		//还有房
        room_text[li_index] = room_list[li_index].getElementsByClassName("cell-star room-bd js_rommimage")[0]; //房间文字描述部分
        room_img[li_index] = room_list[li_index].getElementsByClassName("room-img")[0];    					 //房间描述图片
        room_pay_btn[li_index] = room_list[li_index].getElementsByClassName("dl-btn-mod")[0];                  //房间预定按钮

        show_detail(room_text[li_index]);				//点击文字
        show_detail(room_img[li_index]);			    //点击图片
        room_pay_btn[li_index].onclick = function () {
            //点击预定按钮
            var house_id = $(this).attr('house-id');
            //console.log(house_id);
            goto_pay(house_id);
        }
    }
})




//绑定房间详情页面弹框
function bind_room_html(house_id){
    var str = '<div class="l js_pop_box" house_id='+house_id+' rel="房型弹层html区域">'+
        '<div class="hd js_hd" rel="透明头部"><span class="house_name">高级双床房(包含迪士尼免费早晚接送)</span><span class="a-area js_btn_close"><i class="l-close"></i></span></div>'+
        '<div class="bd js_swrapper" rel="中间带滚动条区域" style="overflow: scroll; position: relative;height: 20rem;"> <div style="transition-timing-function: cubic-bezier(0.1, 0.57, 0.1, 1); transition-duration: 0ms; transform: translate(0px, 0px) translateZ(0px);">'+
        '<div class="js_pop_slide_container">'+
        '<div class="cm-slide cm-slide--full-img swiper-container" id="ui-view-30">'+
        '<ul class="swiper-wrapper js_scroller">'+
        /*'<li class="swiper-slide"> <img src="images/20050n000000eafdr55EB_C_750_400_Q50.jpg_.webp"> </li>'+
        '<li class="swiper-slide"> <img src="images/20030n000000e9njc59D8_C_750_400_Q50.jpg_.webp"> </li>'+  */
        '</ul>'+
        '<div class="cui-slide-nav-new swiper-pagination"></div>'+
        '</div>'+
        '</div>'+
        '<div class="l-base c-box l-tb-border mb5">'+
        '<ul class="base-info">'+
        '<li class="item"><span class="tit c333">面积：</span> <span class="bfc house_area"></span></li>'+
        '<li class="item"><span class="tit c333">规格：</span> <span class="bfc house_rule"></span></li>'+
        '</ul>'+
        '</div>'+
        '<div class="need_konw">'+
        '<div class="need_konw_title">预定须知</div>'+
        '<ul>'+
        '<li>'+
        '<div class="cheng_se">入住限制</div>'+
        '<div class="need_konw_content">仅限大陆身份证</div>'+
        '</li>'+
        '<li>'+
        '<div class="cheng_se">预定提示</div>'+
        '<div class="need_konw_content house_notice"></div>'+
        '</li>'+
        '</ul>'+
        '</div>'+
        '</div> <div style="position: absolute; z-index: 9999; width: 7px; bottom: 2px; top: 2px; right: 1px; overflow: hidden; transform: translateZ(0px); transition-duration: 0ms; opacity: 0;"><div style="box-sizing: border-box; position: absolute; background: rgba(0, 0, 0, 0.498039); border: 1px solid rgba(255, 255, 255, 0.901961); border-radius: 3px; width: 100%; transition-duration: 0ms; height: 348px; transform: translate(0px, 0px) translateZ(0px); transition-timing-function: cubic-bezier(0.1, 0.57, 0.1, 1);"></div></div></div>'+
        '<!--弹框底部start-->'+
        '<div class="ed js_footer" rel="固定底部">'+
        '<ul class="l-pay l-list">'+
        '<li class="item">'+
        '<div class="l-cell-num">'+
        '<p class="clearfix"> <span class="total">1晚总价：</span> <span class="bfc l-price"><small>¥</small></span> </p>'+
        '</div> <button data-ubt-key="c_hotel_oversea_detail_room_sub_reserve" class="l-btn btn--ui3 js_btn_book  "><em class="pay-way  way-yf ">在线付</em>预订</button>'+
        '</li>'+
        '</ul>'+
        '</div>'+
        '<!--弹框底部end-->'+
        '</div>';
    return str;
}


//绑定图片html
function bind_img_html(img_path) {
    var img_str = "";
    for (var i = 0; i < img_path.length; i++) {
        img_str += '<li class="swiper-slide"> <img src=' + img_path[i] + '> </li>';
    }
    $('.swiper-wrapper.js_scroller').append(img_str);
}

//创建房间详情页面
function create_room_html(house_id) {
    var str = bind_room_html(house_id);   //创建html

    $('#ui-view-28').append(str);         //添加html
    $('#ui-view-29').css('display','block');
    url = "hotel.php?mod=index&act=img_ajax&house_id=" + house_id;
    console.log(house_id);
    jQuery.ajax({
        "url": url,
        "type": "get",
        'dataType': 'json',
        "success": function (html) {
            $(".house_area").text(html['house_area']+"");
            $(".house_rule").text(html['house_rule']);
            $(".l-price").html(html['house_wxprice']);
            $(".house_name").html(html['house_name']);
            $(".house_notice").html(html['house_notice'])
            img_path = html['houseimg'];
            console.log(img_path);
            bind_img_html(img_path)   //插入图片

            //调用插件方法
            var swiper = new Swiper('.swiper-container', {loop: true, slidesPerView: 1, grabCursor: true, pagination: {el: '.swiper-pagination',},  });
            var img_total_num = $("#ui-view-28").find(".swiper-slide").length - 2;     //房间详情图片的总数量
            $("#ui-view-28").find(".cui-slide-nav-new").text("1/" + img_total_num);

        },
        "error": function () {
            alert("error");
        }
    });

    room_detail.style.bottom = "0px";
    

    //关闭房间详情页面
    close_detail();
}

//关闭房间详情页面
function close_detail(){
    var room_close = document.getElementsByClassName("js_btn_close")[0];  		//房间详情关闭按钮
    room_close.onclick = function () {
        $('#ui-view-29').css('display','none');
        $('#ui-view-28').html('');      //清空html
        room_detail.style.bottom = "-100%";
    }
}

//显示房间详情页面
function show_detail(obj) {
    obj.onclick = function () {
        var house_id = $(this).attr('house-id');  //获取房型id

        //创建房间详情页面
        create_room_html(house_id);

        /*点击房间详情页面的支付按钮*/
        $('.l-btn.btn--ui3.js_btn_book').on('click',function(){
            goto_pay(house_id);
        })
    }
}

//跳转支付页面
function goto_pay(house_id = "") {
    indate = intime.innerHTML;
    outdate = outtime.innerHTML;
    self.location = encodeURI("./hotel.php?mod=pay&indate=" + indate + "&outdate=" + outdate + "&house_id=" + house_id); //编码
}

//开启时间日历
$('.js_in_out_day').on('click',function() {
    $('.calendar--mask').fadeIn(300);
    console.log('jfdljf')
})


//点击防弹层
$('#ui-view-29').on('click',function() {
//点击防弹层
    $('#ui-view-29').on('click', function () {
        $(this).css('display', 'none');
        $('#ui-view-28').html('');      //清空html
        room_detail.style.bottom = "-100%";
    })
})